package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface DishMapper {
	
	/**
	 * 分页查询菜品
	 */
	Page<DishVO> getDish(DishPageQueryDTO dishPageQueryDTO);
	
	/**
	 * 根据分类id查询数量
	 *
	 * @param categoryId
	 * @return
	 */
	@Select("select count(*) from dish where category_id = #{categoryId}")
	Integer getDishCategory(Long categoryId);
	
	/**
	 * 新增菜品
	 *
	 * @param dish
	 */
	@AutoFill(OperationType.INSERT)
	void addDish(Dish dish);
	
	/**
	 * 根据id查询
	 *
	 * @param id
	 * @return
	 */
	@Select("select * from dish where id = #{id}")
	Dish getDishId(Long id);
	
	/**
	 * 起售/停售菜品
	 *
	 * @param id
	 * @param status
	 */
	@Update("update dish set status = #{status},update_time=#{updateTime},update_user=#{updateUser} where id = #{id}")
	void putDishStatus(Long id, Integer status, LocalDateTime updateTime, Long updateUser);
	
	/**
	 * 删除菜品
	 *
	 * @param ids
	 */
	void deleteDish(List<Long> ids);
	
	@AutoFill(OperationType.UPDATE)
	void putDish(Dish dish);
	
	@Select("select d.*,c.name category_name from dish d left outer join category c on d.category_id=c.id where d" +
		".category_id=#{categoryId}")
	List<DishVO> getCategoryId(Long categoryId);
	
	@Select("select count(*) from dish where status=#{status}")
	Integer countNumber(Integer status);
}
